package web;

import com.alibaba.fastjson.JSONArray;
import pojo.SmbmsRole;
import service.SmbmsRoleService;
import service.impl.SmbmsRoleServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
@WebServlet(value = "/showRole")
public class ShowRoleServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws
            ServletException, IOException {
        this.doPost(req, resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf-8");
        req.setCharacterEncoding("utf-8");
        System.out.println("------------------------");
        SmbmsRoleService smbmsRoleService=new SmbmsRoleServiceImpl();
        try {
            List<SmbmsRole> smbmsRoles = smbmsRoleService.queryRole();
            PrintWriter writer = resp.getWriter();
            writer.write(JSONArray.toJSONString(smbmsRoles));
            writer.flush(); //刷新
            writer.close(); //关闭流
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

